import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;

public class Test {
    public static void main(String[] args) {
        //标准库中的线程池
        //ExecutorService pool= Executors.newFixedThreadPool(10)
       // ExecutorService pool=Executors.newCachedThreadPool();
        ExecutorService pool=Executors.newSingleThreadExecutor();
    }
    public static void main1(String[] args) throws InterruptedException {
        //标准库里面的阻塞队列
        BlockingQueue<Integer> blockingQueue=new LinkedBlockingQueue<>();
       Thread t=new Thread(()->{
           int num=0;
           while (true){
               try {
                   System.out.println("生产了"+num);
                   blockingQueue.put(num);
                   num++;
               } catch (InterruptedException e) {
                   throw new RuntimeException(e);
               }
           }
       });
       Thread t1=new Thread(()->{
           while (true){
               try {
                   int num=blockingQueue.take();
                   System.out.println("消费了"+num);
               } catch (InterruptedException e) {
                   throw new RuntimeException(e);
               }
           }
       });
       t.start();
       t1.start();

    }

}
